# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=mdbook-linkcheck
pkgver=0.7.7
pkgrel=1
pkgdesc='A mdbook backend which will check all links in a document are valid'
arch=('loong64' 'x86_64')
url='https://github.com/Michael-F-Bryan/mdbook-linkcheck'
license=('MIT')
depends=('mdbook')
makedepends=('git' 'rust')
options=('!lto')
_commit='bed5ebbae325d41bdccec382ecbe30f795738ca2'
source=("$pkgname::git+$url.git#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # download dependencies
  find -name Cargo.lock -exec rm -f {} \;
  mkdir -p .cargo
  cat >> .cargo/config <<EOF
[source.crates-io]
registry = "https://gitee.com/yetist/crates.io-index"
EOF
  cargo fetch --target "`uname -m`-unknown-linux-gnu"
}

build() {
  cd "$pkgname"

  cargo build --release --all-features
}

check() {
  cd "$pkgname"

  cargo test --frozen --all-features
}

package() {
  cd "$pkgname"

  # binary
  install -vDm755 -t "$pkgdir/usr/bin" "target/release/$pkgname"

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}
